package com.shenglue.ssi.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.shenglue.ssi.domain.Supp;
import com.shenglue.ssi.service.SuppService;

public class SuppAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Supp supp;     // 对应的 Bean
	private int suppId;    // 删除/修改 的 记录之Id
	private SuppService suppService;  // 依赖的 Service

	public SuppService getSuppService() {
		return suppService;
	}

	public void setSuppService(SuppService suppService) {
		this.suppService = suppService;
	}

	public Supp getSupp() {
		return supp;
	}

	public void setSupp(Supp supp) {
		this.supp = supp;
	}

	public int getSuppId() {
		return suppId;
	}

	public void setSuppId(int suppId) {
		this.suppId = suppId;
	}

	public SuppAction() {
	}


	/**
	 * 查询所有供应商信息方法
	 */
	public String queryAll() throws Exception {
		List<Supp> list = suppService.selectAllSupp();
		if(list!=null){
			HttpServletRequest request = ServletActionContext.getRequest();
			request.setAttribute( "suppList", list );
		}else{
			// 不能认为是错误，因为一开始是没有数据的  return INPUT;
		}
		return SUCCESS;
	}

	/**
	 * 增加供应商记录方法
	 */
	public String addNew() throws Exception {
		boolean flag = suppService.saveSupp( supp );
		if(flag==true){
			return SUCCESS;
		}else{
			return ERROR;
		}
	}

	/**
	 * 删除供应商记录方法
	 */
	public String delete() throws Exception {

		// 获取request对象
		boolean flag = suppService.deleteSupp( suppId );
		if( flag == true ) {
			return SUCCESS;
		}else{
			return ERROR;
		}
	}

	/**
	 * 修改供应商记录方法
	 */
	public String update() throws Exception {

		boolean flag = suppService.updateSupp( supp );
		if( flag == true ) {
			return SUCCESS;
		}else{
			return ERROR;
		}
	}
}
